import React, { useState, useEffect } from 'react';
import { Form, Button, Space } from 'antd';
import { goBack, componentsMap } from '@/utils/util';
import API from '@/api/xjindex.js';
import FileList from '@/components/FileLists';

const patrolManageCheck = ({ history }) => {
  const [form] = Form.useForm();
  const [fileList, setfileList] = useState([]);
  const TableList = [
    {
      label: '巡检标题',
      name: 'pollingTitle',
      type: 'input',
      isremark: true,
      otherProps: {
        disabled: true,
      },
    },
    {
      label: '单位名称',
      name: 'orgName',
      type: 'input',
      otherProps: {
        disabled: true,
      },
    },
    {
      label: '巡检时间',
      name: 'pollingTime',
      type: 'input',
      otherProps: {
        disabled: true,
      },
    },
    {
      label: '创建人',
      name: 'createName',
      type: 'input',
      otherProps: {
        disabled: true,
      },
    },
    {
      label: '创建时间',
      name: 'createTime',
      type: 'input',
      otherProps: {
        disabled: true,
      },
    },
    {
      label: '备注说明',
      name: 'remarks',
      type: 'textarea',
      otherProps: {
        disabled: true,
      },
      isremark: true,
    },
  ];

  function initList() {
    API.selectPomById({ id: history.location.query.id }).then((res) => {
      if (res) {
        form.setFieldsValue(res.t);
        setfileList(res.t.pollingManagementFileList);
      }
    });
  }
  useEffect(() => {
    initList();
  }, []);
  return (
    <div className="main-x">
      <Form form={form}>
        <div className="base-title">巡检信息</div>
        <div className="bgf">
          <div className="ant-form-inline form-x max-x">
            {TableList.map((item) => {
              return (
                <Form.Item
                  key={item.name}
                  label={item.label}
                  name={item.name}
                  className={item.isremark ? 'block' : ''}
                >
                  {componentsMap(item.type, item.otherProps, true)}
                </Form.Item>
              );
            })}
          </div>
        </div>
        <div className="base-title mt20">附件信息</div>
        <div className="form-x bgf" style={{ paddingBottom: '16px' }}>
          <Form.Item label="附件信息" className="block">
            {
              <FileList
                fileList={fileList}
                downloadUrl="/polling/management/download"
              />
            }
          </Form.Item>
        </div>
        <div className="footer-x">
          <Space size={18}>
            <Button type="primary" className="cancel-btn" onClick={goBack}>
              返回
            </Button>
          </Space>
        </div>
      </Form>
    </div>
  );
};
export default patrolManageCheck;
